conv_rate = zeros(72,13); % rate of convergence
conv_step = zeros(72,13); % average step of convergence (if converged), % 0 if all didnt converge
glbl_optm = zeros(72,13); % rate of finding global optima (out of N)

N = 128;

currentFolder = fileparts(mfilename('fullpath')); % Get script folder
files = dir(fullfile(currentFolder, '*.mat')); % Get all .mat files in the folder

for k = 1:length(files)
    fileName = fullfile(currentFolder, files(k).name); % Get full file path
    data = load(fileName); % Load the .mat file
    disp(['Loaded: ', files(k).name]); % Display the file name

    % Process data here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if size(data.data)*[0;1] ~= N
        % disp(['Loaded: ', files(k).name]); % Display the file name
        error("incomplete dataset at file:")
    end

    % matrix(i,j)
    c_0 = data.c_0;
    beta = data.beta;
    i = round((c_0-1.0)*10+1);
    j = round(beta*20+1);

    conv_count = 0;
    conv_step_total = 0;
    glbl_optm_count = 0;

    for l = 1:N
        if data.data(l).id ~= 0
            conv_count = conv_count + 1;
            conv_step_total = conv_step_total + data.data(l).k_end;
        end
        if data.data(l).id == 4
            glbl_optm_count = glbl_optm_count + 1;
        end
        
        if conv_count == 0
            conv_rate(i,j) = 0;
            conv_step(i,j) = 0;
            glbl_optm(i,j) = 0;
        else
            conv_rate(i,j) = conv_count/N;
            conv_step(i,j) = conv_step_total/conv_count;
            glbl_optm(i,j) = glbl_optm_count/N;
        end

    end

end